<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 要求：输出一个数组：[1,2,3,9]
      const arr2 = [1, 2, 3, 2, 9]
      const arr1 = []
      //第一种
      // arr2.forEach((item) => {
      //   if (arr1.indexOf(item) == -1) {
      //     arr1.push(item)
      //   }
      // })
      // console.log(arr1)

      //第二种
      // for (let i = 0; i < arr2.length; i++) {
      //   for (let j = 0; j < arr2.length; j++) {
      //     if (arr2[i] == arr2[j] && i != j) {
      //       arr2.splice(j, 1)
      //     }

      //   }
      // }
      // console.log(arr2)

      //第三种
      const res = new Set(arr2)
      console.log(res)
    </script>
  </body>
</html>
